package com.skateboard.reelviewtest;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.skateboard.reelviewtest.rotate.Rotate3dAnimation;


public class Rotate3DActivity extends AppCompatActivity {
    ImageView cart;
    Rotate3dAnimation rotate3dAnimation;
    Handler handler=new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            test();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rotate3_d);
        cart = findViewById(R.id.iv_cart);
        handler.sendEmptyMessageDelayed(0,100);

    }

    public void test(){

        float centerX = cart.getWidth()/2.0f;
        float centerY = cart.getHeight()/2.0f;
        if (centerX == 0 || centerY == 0) {
            //调用该方法getMeasuredWidth()，必须先执行measure()方法，否则会出异常。
            cart.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            //获取该view在父容器里面占的大小
            centerX = cart.getMeasuredWidth() / 2.0f;
            centerY = cart.getMeasuredHeight() / 2.0f;
        }

        rotate3dAnimation = new Rotate3dAnimation(this,0,180,centerX,centerY,200f,false);
        rotate3dAnimation.setDuration(1000);
        rotate3dAnimation.setInterpolator(new DecelerateInterpolator());//设置动画变速
        // cart.startAnimation(rotate3dAnimation);

        ScaleAnimation scaleAnimation = new ScaleAnimation(0.5F,1.5f,0.5F,1.5f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);


        AnimationSet set = new AnimationSet(false);
        set.addAnimation(rotate3dAnimation);
        set.addAnimation(scaleAnimation);
        set.setDuration(1000);
        set.setFillAfter(true);
        cart.startAnimation(set);
    }
}